const path = require('path')
const execSync = require('child_process').execSync

/**
 * 获取根路径
 */
exports.getRootPath = function () {
    return path.resolve(__dirname, '../../')
}
//   获取版本号
exports.getPkgVersion = function () {
    return require(path.join(exports.getRootPath(), 'package.json')).version
}

/**
 * 打印版本号
 */
exports.printPkgVersion = function () {
    const taroVersion = exports.getPkgVersion()
    console.log(` ToolKits v${taroVersion} `)
    console.log('------------------------------')
    console.log('|                            |')
    console.log('|        welcome to          |')
    console.log('|                            |')
    console.log('|      T o o k i t s         |')
    console.log('|      _ _ _ _ _ _ _         |')
    console.log('|                            |')
    console.log('-------------7-----------------')
}
exports.shouldUseYarn = function () {
    try {
        execSync('yarn --version', { stdio: 'ignore' })
        return true
    } catch (e) {
        return false
    }
}

exports.shouldUseCnpm = function () {
    try {
        execSync('cnpm --version', { stdio: 'ignore' })
        return true
    } catch (e) {
        return false
    }
}